﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

/// <summary>
/// Visitor 的摘要说明
/// </summary>
public class Visitor
{
    public Visitor()
    {
    }
    public DataSet GetLM(int start, int end)
    {
        SqlConnection con = new SqlConnection(DbHelper.strCon);
        SqlCommand com = new SqlCommand();
        com.Connection = con;
        com.CommandText = "GetlM";
        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add(new SqlParameter("@startIndex", start));
        com.Parameters.Add(new SqlParameter("@endIndex", end));
        con.Open();
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(com);
        da.Fill(ds);
        con.Close();
        return ds;
    }
    public int LMCount()
    {
        int num = 0;
        SqlConnection con = new SqlConnection(DbHelper.strCon);
        SqlCommand com = new SqlCommand();
        com.Connection = con;
        com.CommandText = "GetLMCount";
        com.CommandType = CommandType.StoredProcedure;
        con.Open();
        SqlDataReader dr = com.ExecuteReader();
        while (dr.Read())
        {
            num = Convert.ToInt32(dr[0]);
        }
        con.Close();
        return num;
    }
    public bool AddLMessage(string NikeName,string Content,string PhoneNum,string IPforAddress)
    {
        SqlConnection con = new SqlConnection(DbHelper.strCon);
        SqlCommand com = new SqlCommand();
        com.Connection = con;
        com.CommandText = "AddLMessage";
        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add(new SqlParameter("@NikeName", NikeName));
        com.Parameters.Add(new SqlParameter("@Content", Content));
        com.Parameters.Add(new SqlParameter("@PhoneNum", PhoneNum));
        com.Parameters.Add(new SqlParameter("@IPforAddress", IPforAddress));
        con.Open();
        int n = com.ExecuteNonQuery();
        con.Close();
        if (n > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
       
    }
    public int GetNotLMCount()
    {
        int num = 0;
        SqlConnection con = new SqlConnection(DbHelper.strCon);
        SqlCommand com = new SqlCommand();
        com.Connection = con;
        com.CommandText = "GetNotLMCount";
        com.CommandType = CommandType.StoredProcedure;
        con.Open();
        SqlDataReader dr = com.ExecuteReader();
        while (dr.Read())
        {
            num = Convert.ToInt32(dr[0]);
        }
        con.Close();
        return num;
    }

}